package top.i51213.fastaction.util;

import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;

import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

public class Util {
    public static int tryParseInt(String s, int _default) {
        try {
            return Integer.parseInt(s);
        } catch (Exception e) {
            return _default;
        }
    }

    public static boolean checkSelfPermission(Context context, String permission) {
        return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
    }
    public static boolean checkSelfPermission(Activity context, String permission,int VersionCode) {
        if(Build.VERSION.SDK_INT>=VersionCode){
            return ContextCompat.checkSelfPermission(context, permission) == PackageManager.PERMISSION_GRANTED;
        }
        return true;
    }
}
